package com.woniuxy.article.mapper;


import com.hc.entity.Paper;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @ClassName articleMapper
 * @Description
 * @Author TJ
 * @Date 2022/10/19 19:14
 * @Version 1.0
 **/
@Mapper
public interface ArticleMapper {
    @Select("SELECT * FROM hc_paper WHERE TEXT LIKE '%${message}%'")
    List<Paper> getByMessage(String message);

    //用户查看自己发表文章被点过赞的（由点赞数从高到低）
    @Select("select * from hc_paper where user_id=#{uid} order by likenum desc")
    @Results(
            {
                    @Result(column = "id",property = "id" ,id = true),
                    @Result(column = "title",property = "title"),
                    @Result(column = "vaddress",property = "vaddress"),
                    @Result(column = "iaddress",property = "iaddress"),
                    @Result(column = "text",property = "text"),
                    @Result(column = "likenum",property = "likenum"),
                    @Result(column = "unlikenum",property = "unlikenum"),
                    @Result(column = "discount",property = "discount"),
                    @Result(column = "id",property = "comments",many = @Many(select = "com.woniuxy.article.mapper.CommentMapper.getByPaperId",fetchType = FetchType.LAZY))
            }
    )
    List<Paper> getsupById(Integer uid);

    //用户查看自己文章（由最新时间排序查找）
    @Select("select * from hc_paper where user_id=#{uid} order by id desc")
    @Results(
            {
                    @Result(column = "id",property = "id" ,id = true),
                    @Result(column = "title",property = "title"),
                    @Result(column = "vaddress",property = "vaddress"),
                    @Result(column = "iaddress",property = "iaddress"),
                    @Result(column = "text",property = "text"),
                    @Result(column = "likenum",property = "likenum"),
                    @Result(column = "unlikenum",property = "unlikenum"),
                    @Result(column = "discount",property = "discount"),
                    @Result(column = "id",property = "comments",many = @Many(select = "com.woniuxy.article.mapper.CommentMapper.getByPaperId",fetchType = FetchType.LAZY))
            }
    )
    List<Paper> gettimeById(Integer uid);

    //通过id查询文章
    @Select("select * from hc_paper where id=#{id}")
    @Results(
            {
                    @Result(column = "id",property = "id",id = true),
                    @Result(column = "title",property = "title"),
                    @Result(column = "text",property = "text")
            }
    )
    Paper getById(Integer id);

    //用户删除自己文章
    @Delete("delete from hc_paper where id=#{id}")
    void del(Integer id);
    //删除点赞表
    @Delete("delete from hc_agree where paper_id=#{pid}")
    void delagree(Integer pid);
    //用户修改自己的文章
    @Update("update hc_paper set text=#{text},title=#{title} where id=#{id}")
    void update(Paper paper);


}
